﻿
// 获取当前日期时间
var now = new Date();
var year = now.getFullYear();
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var day = ("0" + now.getDate()).slice(-2);
var hours = ("0" + now.getHours()).slice(-2);
var minutes = ("0" + now.getMinutes()).slice(-2);
//var seconds = ("0" + now.getSeconds()).slice(-2);
var serialNumber = "FJ" + year + month + day + hours + minutes;
var inputElement = document.getElementById('ReInCode2');
inputElement.value = serialNumber;


var obj1 = {
    "createdBy": "",
    "createdDate": "",
    "updatedBy": "",
    "updatedDate": "",
    "deletedBy": "",
    "deletedDate": "",
    "isDeleted": false,
    "reinspectionId": "",
    "reinspectionCode": "",
    "reinspectionName": "",
    "reinspectionNumber": "",
    "reinspectionNote": "",
    "reinspectionSarte": "",
    "heGeSarte": "",
    "reinspectionTime": "",
    "reName": "",
    "rawMaterialQualityId": ""
};

layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
    //反填显示复检信息
    //反填

    $(function () {
        fantian1();

    })
    //反填原料质检信息消息
    function fantian1() {
        // 发送AJAX请求获取数据
        console.log(localStorage.getItem("rawMaterialQualityId"))
        $.ajax({
            type: "get",
            url: "/Quality/RawGetid",
            data: {
                RawMaterialQualityId: localStorage.getItem("rawMaterialQualityId"),
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var ter = JSON.parse(res)
                console.log(ter.data)

                $(ter.data).each(function () {
                    $('#QualityNumber2').val(this.qualityNumber);
                    $('#QualityName2').val(this.qualityName);
                    $('#QualityTime2').val(this.qualityTime.substring(0,10));
                    $('#Qualityer2').val(this.qualityer);
                    $('#Supplier2').val(this.supplier);
                    $('#MaterialNumber2').val(this.materialNumber);
                    $('#MaterialName2').val(this.materialName);
                    $('#Unit2').val(this.unit);
                    $('#SpecificationsModel2').val(this.specificationsModel);
                    $('#batchNumber2').val(this.batchNumber);
                    $('#Size2').val(this.size);
                    $('#ReinspectionNumber2').val(this.unqualifiedQuantity);
                   
                })

            },

        });


    }
    //添加复检信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('allocationReInface');
        field.allocationReInfaceList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field);//field.products
      
        obj1.reinspectionCode = $("#ReInCode2").val()
        obj1.reinspectionName = $("#ReinspectionName2").val()
        obj1.reinspectionNumber = $("#ReinspectionNumber2").val()
        obj1.reinspectionNote = $("#ReinspectionNote2").val()
        obj1.reinspectionSarte = "待复检"
        obj1.heGeSarte = $("[name='HeGeSarte2']:checked").val()
        obj1.reinspectionTime = $("#ReinspectionTime2").val()
        obj1.reName = $("#ReName2").val()
        obj1.rawMaterialQualityId = localStorage.getItem("rawMaterialQualityId")
            obj1.createdBy = ""
       
        console.log(obj1)
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Quality/AddReIn',
            type: 'post',
            data: {
                model: obj1, token: localStorage.getItem("token")
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(field);
                console.log(res);
                if (res.code > 0) {
                    layer.alert("添加成功");
                    //location.href = '/Quality/ReInfIndexShow'
                } else {
                    layer.alert("添加失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

})
